using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter04
{
	/// <summary>
	/// Example06: The Stranded Explorers
	/// A plane drops a package of supplied to a party of 
	/// explorers, as shown in Figure 4.15. If the plane is 
	/// traveling horizontally at 40.0 m/s and is 100 m above the 
	/// ground, where does the package strike the ground relative 
	/// to the point at which it is released? 181 m
	/// </summary>
	public class Example06
	{
		public Example06()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Velocity v = new L.Velocity();
			v.X = 40.0;

            Science.Mathematics.Calculus.PolynomialFunction poly = new Science.Mathematics.Calculus.PolynomialFunction();
			poly.MaximumPower = 2;
			poly.Which = 0;
			poly.Coefficient = 100.0;
			poly.Which = 1;
			poly.Coefficient = 0.0;
			poly.Which = 2;
			poly.Coefficient = -0.5*L.Constant.AccelerationOfGravity;
			poly.FindRoot();
			double time1 = poly.Root[0].Real;
			double time2 = poly.Root[1].Real;
			double solution;
			if(time2 > time1) solution = time2;
			else solution = time1;

			double distance = v.X*solution;
			result+=Convert.ToString(distance);
		}
	}
}
